#!/bin/bash

source /AIR_FLASH/script/air.conf
source /AIR_FLASH/script/shcommon

VER_NAME="$1"

Info "APP rollback start..."
killall -9 monitor.sh
killall -9 $APP_NAME
killall -9 usb.sh
killall -9 bondCheck.sh

#sleep 2
if [ ! -f "${upgrade_DIR}/backup/${APP_NAME}" ] ; then
        if [ -f "${upgrade_DIR}/elder/${APP_NAME}" ] ; then
	    cp ${upgrade_DIR}/elder/* ${prefix} -r
	else
	    if [ -f ${upgrade_DIR}/$app_cur_filename ] ; then
		Info "${prefix}/script/upgrade.sh $app_cur_filename"
		${prefix}/script/upgrade.sh $app_cur_filename
#upgrade.sh restart app
		exit 0
	    fi
	fi
else 
	cp ${upgrade_DIR}/backup/* ${prefix} -r
fi

Info "APP rollback done..."

cd $prefix/script
./monitor.sh
./boot.sh
./usb.sh &

exit 0

